#!/usr/bin/perl
#
use strict;
use warnings;
use Tk;

unless (@ARGV) {
	show_usage();
	exit 1;
}

if ($ARGV[0] eq '-h' || $ARGV[0] eq '--help') {
	show_uage();
	exit 0;
}

my $file = $ARGV[0];

unless (-f $file) {
	print("File '$file' does not exist.\n");
	show_usage();
	exit 1;
}


my $format;

if    ($file =~ m/\.xpm$/i) {
	$format = 'xpm';
}
elsif ($file =~ m/\.gif$/i) {
	$format = 'gif';
}
elsif ($file =~ m/\.png$/i) {
	$format = 'png';
}


my $mw = new MainWindow(-title => "Tkdisplay - $file");
my $image = $mw -> Photo(-file => $file, -format => $format);

$mw -> Label(-image => $image) -> pack();

MainLoop();


sub show_usage {
	print(
		"\n",
		"Usage:\n",
		"    tkdisplay.pl <image file>\n",
		"\n",
		"Recognized formats include XBM, XPM, BMP, JPG, PPM/PGM, PNG\n",
		"and all other formats recognized by the Tk library.\n\n");
	return;
}




